package com.ys.day28.socket;

import java.net.Socket;

/**
 * 描述: P2SocketAddress
 * 查看访问对象的基本信息,模仿客户端去ping命令
 *
 * @author CodeYang
 * @version 2021/1/8 19:12
 */
public class P2Socket模仿Ping命令 {

    public static void main(String[] args) throws Exception {


        boolean result = pingAddress("baidu.com", 80);
        System.out.println(result);
    }

    /**
     *  判断 链接是否成功建立
     * @return 判断 链接是否成功建立
     */
    private static boolean pingAddress(String address,int port) {
        try (
                Socket socket = new Socket(address, port);
        ) {
            System.out.println("connection success :"+socket);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }
}
